package com.example.service.pet.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mapper.PetMapper;
import com.example.pojo.Pet;
import com.example.service.pet.PetExploreService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author Lexin Huang
 */
@Service
public class PetExploreServiceImpl implements PetExploreService {

    private final PetMapper petMapper;

    public PetExploreServiceImpl(PetMapper petMapper) {
        this.petMapper = petMapper;
    }

    @Override
    public List<Pet> getSameBreedPets(String breed) {
        QueryWrapper<Pet> petQueryWrapper = new QueryWrapper<>();
        petQueryWrapper.select("pet_name", "petPortraitPath", "pet_species", "pet_introduction")
                        .eq("is_pet_overt", true)
                        .eq("pet_species", breed);
        return Objects.requireNonNullElse(petMapper.selectList(petQueryWrapper), new ArrayList<>());
    }


    private List<Pet> getByBreed(String breed) {
        QueryWrapper<Pet> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pet_species", breed).eq("is_pet_overt", true);
        List<Pet> pets = petMapper.selectList(queryWrapper);
        return Objects.isNull(pets) ? new ArrayList<>() : pets;
    }
}
